<?php
/**
 * This engine is responsible for interfacing with Swish-e
 *
 * @author Rob Young <rob@roryoung.co.uk>
 * @package forage.engine.swishe
 */
class ForageSwisheEngine extends ForageEngine
{
  // TODO: this shouldn't be a constant
  const SWISHE_COMMAND = 'swish-e';
  
  private $path;

  public function initialize($dsn, $config)
  {
    $this->path = $dsn;
  }

  public function search(ForageQuery $query)
  {
    $cmd    = self::SWISHE_COMMAND . " -w '" . addslashes($query->query_string) . "' -f " . $this->path . " -b 0 -m 10";
    $handle = popen($cmd, 'r');
    if (!$handle) {
      throw new ForageEngineException("Failed to run command " . $cmd);
    }
    // todo: parse the search output
  }

  public function add(ForageDocument $document)
  {
    
  }
}
